/*
 * game.h
 *
 *  Created on: 2011-9-27
 *  Author    : gelif(admin@gelif.net)
 */

#ifndef GAME_H_
#define GAME_H_

#include <wx/string.h>

class Coordinate
{
public:
    enum Status
    {
        NONE = 0, BLACK = 1, WHITE = 2
    };
    Coordinate(int x, int y);
    ~Coordinate();
    int getX();
    void setX(int);
    int getY();
    void setY(int y);
    bool operator<(const Coordinate& coordinate) const;

private:
    int x;
    int y;
};

class Fiveline
{
public:
    Fiveline(int startX, int startY, int endX, int endY);
    ~Fiveline();
    int startX;
    int startY;
    int endX;
    int endY;
};

class GelifMove
{
public:
    GelifMove(int x, int y, Coordinate::Status);
    GelifMove(wxChar*);
    ~GelifMove();
    wxChar* serialize() throw ();
    void deserialize(wxChar*);
    int x;
    int y;
    Coordinate::Status status;
};

class Game
{
public:
    enum GameStatus
    {
        IS_WAITING = 0, IS_READY = 1, IS_ON = 2, BLACK_WIN = 3, WHITE_WIN = 4, IS_END = 5
    };
    enum ForbiddenStatus
    {
        NO, THREE_THREE, FOUR_FOUR, LONG
    };
    static const int MAX_RANKS = 15; // max x
    static const int MAX_FILES = 15; // max y
    Game();
    ~Game();
    void initStatus();
    GameStatus nextStatus();
    ForbiddenStatus checkForbidden(int x, int y);
    ForbiddenStatus checkForbidden(Coordinate, int adjSame, int direction);
    void move(int x, int y, Coordinate::Status status);
    void move(int x, int y);
    void move(Coordinate);
    Coordinate::Status getSatusByCoordinate(Coordinate);
    wxString serialize() throw (); //序列化
    void deserialize(wxString&); //反序列化
    //GelifMove& restore();
    Coordinate::Status check();
    void resign();  // 认输

    Coordinate::Status points[MAX_RANKS][MAX_FILES];
    GameStatus status;
    Coordinate::Status mypiece;
    Fiveline* fiveline;
    bool is_my_turn;
};
#endif /* GAME_H_ */
